package com.haotian.img;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 * 图片转换类
 * 
 * @author 张昊天 2017年11月8日
 */
public class ConvertImageFile {

	/**
	 * PNG转JPG
	 * @param srcPath
	 * @param toPath
	 */
	public static void png2Jpg(String srcPath, String toPath) {
		BufferedImage bufferedImage;
		try {
			bufferedImage = ImageIO.read(new File(srcPath));
			BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
					BufferedImage.TYPE_INT_RGB);
			newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);
			ImageIO.write(newBufferedImage, "jpg", new File(toPath));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
